package com.blockmeta.bbs.businesslibrary.widget;

import android.content.Context;
import androidx.constraintlayout.widget.Group;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.businesslibrary.R;

/**
 * @author AirThor
 * @date 2019/9/26.
 * 投票封装
 */
public class DebateView extends FrameLayout {
    private Group mNormalGroup,mUnderGroup;
    private TextView mPositiveViewpoint,mNegativeViewpoint,mPositiveViewpointUnder,mNegativeViewpointUnder;
    private DebateBar mVoteBar;
    private ImageView mPic;

    public DebateView(Context context) {
        super(context);
        initialize(context);
    }

    public DebateView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initialize(context);
    }

    public DebateView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context);
    }

    private void initialize(Context context){
        inflate(context, R.layout.view_vote,this);
        mNormalGroup = findViewById(R.id.group_normal);
        mUnderGroup = findViewById(R.id.group_under);
        mPositiveViewpoint = findViewById(R.id.tv_positive_viewpoint);
        mNegativeViewpoint = findViewById(R.id.tv_negative_viewpoint);
        mPositiveViewpointUnder = findViewById(R.id.tv_positive_viewpoint_under);
        mNegativeViewpointUnder = findViewById(R.id.tv_negative_viewpoint_under);
        mVoteBar = findViewById(R.id.v_vote);
        mPic = findViewById(R.id.iv_img);
    }

    public void setPic(String imgUrl){
        LoadPicUtil.load(imgUrl,mPic);
        mNormalGroup.setVisibility(GONE);
        mUnderGroup.setVisibility(VISIBLE);
    }

    public void setViewpoints(String positive,String negative){
        mPositiveViewpoint.setText(positive);
        mPositiveViewpointUnder.setText(positive);
        mNegativeViewpoint.setText(negative);
        mNegativeViewpointUnder.setText(negative);
    }

    public void setVoteCounts(int red,int blue){
        mVoteBar.setVoteCounts(red,blue);
    }

    public void setVoteActive(DebateBar.Button which, boolean active){
        mVoteBar.setActive(which,active);
    }

    public void resetState(){
        mVoteBar.resetState();
    }

    public void setVoteActiveAndUpdateCounts(DebateBar.Button which, boolean active){
            mVoteBar.setActiveAndUpdateCount(which,active);
    }

    public void setVoteClickListener(DebateBar.OnVoteBarClickListener onVoteBarClickListener){
        mVoteBar.setOnVoteBarClickListener(onVoteBarClickListener);
    }
}
